<template>
    <div>
        <el-row :gutter="30">
            <el-col :span="16">
                <el-card shadow="hover" style="height:500px;width:1000px;">
                    <schart class="schart" canvasId="pie" :options="options" :key="updateKey"></schart>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import Schart from "vue-schart";
import {ref, reactive, inject} from "vue";
import { getBaseData, getPieData } from '../../api'
export default {
    name: "statistic-pie",
    components: { Schart },
    setup() {
        const updateKey = ref(0);
        let options = {
            type: "pie",
            title: {
                text: "服装品类销售饼状图",
            },
            legend: {
                position: "left",
            },
            bgColor: "#fbfbfb",
            labels: [
                "采购总金额",
                "销售总金额",
            ],
            datasets: [
                {
                    data: [10, 10],
                },
            ],
        };
        const fetchBaseData = () => {
            getPieData().then(res => {
                if (res.code === 200) {
                    let d = res.data.barDataVO;
                    options.datasets[0].data[0] = d.inside;
                    options.datasets[0].data[1] = d.price;
                    updateKey.value += 1;
                }
            })
        };
        fetchBaseData();

        return {
            options,
            updateKey
        };
    },
};
</script>

<style scoped>
.el-row {
    margin-bottom: 20px;
}

.grid-content {
    display: flex;
    align-items: center;
    height: 100px;
}

.grid-cont-right {
    flex: 1;
    text-align: center;
    font-size: 14px;
    color: #999;
}

.grid-num {
    font-size: 30px;
    font-weight: bold;
}

.grid-con-icon {
    font-size: 50px;
    width: 100px;
    height: 100px;
    text-align: center;
    line-height: 100px;
    color: #fff;
}

.grid-con-1 .grid-con-icon {
    background: rgb(45, 140, 240);
}

.grid-con-1 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-2 .grid-con-icon {
    background: rgb(100, 213, 114);
}

.grid-con-2 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-3 .grid-con-icon {
    background: rgb(242, 94, 67);
}

.grid-con-3 .grid-num {
    color: rgb(242, 94, 67);
}

.user-info {
    display: flex;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 2px solid #ccc;
    margin-bottom: 20px;
}

.user-avator {
    width: 120px;
    height: 120px;
    border-radius: 50%;
}

.user-info-cont {
    padding-left: 50px;
    flex: 1;
    font-size: 20px;
    color: #999;
}

.user-info-cont div:first-child {
    font-size: 30px;
    color: #222;
}

.user-info-list {
    font-size: 24px;
    color: #999;
    line-height: 40px;
}

.user-info-list span {
    margin-left: 70px;
}

.member span {
    display: inline-block;
    padding-top: 8px;
    padding-bottom: 8px;
}
.mgb20 {
    margin-bottom: 20px;
}

.todo-item {
    font-size: 14px;
}

.todo-item-del {
    text-decoration: line-through;
    color: #999;
}

.schart {
    width: 800px;
    height: 400px;
}
</style>
